<?php
/**
 * @category 	Dir.php
 * @author 		Sung Hoon, Cho (akdddnet@gmail.com)
 * @since		2011. 7. 5.
 * @license		BSD License
 * @version		0.1
 * 
 * 
 * http://phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=71199&sca=&sfl=wr_subject%7C%7Cwr_content&stx=%B5%F0%B7%BA%C5%E4%B8%AE&sop=and&page=2
 */


// directory
class Dir {
	
	public function getDirList($dirname) {
		
		$directory = array();
		
		$files = new DirectoryIterator($dirname);
		foreach ($files as $fileinfo) {			
			if ($fileinfo->isDir() && !$fileinfo->isDot()) {
	        	array_push($directory, $fileinfo->getFilename());
	        }
		}
		
		return $directory;
	}
	
	
	public function getFileList($dirname) {
		
		$return = array();
		
		$files = new DirectoryIterator($dirname);
		foreach($files as $fileinfo) {
			if($fileinfo->isFile()) {
				$f = new stdClass;
				$f->name = $fileinfo->getFilename();
				$f->size = $fileinfo->getSize();
				$f->path = $fileinfo->getPath();
				$f->pathname = $fileinfo->getPathname();
				
				array_push($return, $f);
			}
		}
		
		return $return;
	}
	
	
	public function mkdir($dirname, $permission=707) {
		try {
			// dirname이 빈값인지 체크.
			if(!Common::isNullOrEmpty($dirname)) {
				
				// 디렉토리가 존재하지 않을 경우.
				if(!is_dir($dirname)) {
					mkdir($dirname, $permission);
				}
			} else {
				throw new Exception("생성할 폴더명이 전달되지 않았습니다.");
			}
		} catch (Exception $e) {
			throw new Exception($e);
		}
	}
}